package com.resou.reader.mine.consumerecord;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.resou.reader.R;
import com.resou.reader.api.entry.ConsumptionDetailBean;
import com.resou.reader.utils.DateUtils;
import com.resou.reader.utils.log.DLog;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ${Garrett} on 2018/9/21.
 * Contact me krouky@outlook.com
 */
public class ConsumechildAdapter extends RecyclerView.Adapter {

    private List<ConsumptionDetailBean.ConsumptionItemsBean> secondBeanSparseArray = new ArrayList<>();//存储每条流水数据

    private Context mContext;

    public ConsumechildAdapter(Context mContext) {
        this.mContext = mContext;
    }


    public void setSecondBeanSparseArray(List<ConsumptionDetailBean.ConsumptionItemsBean> secondBeanSparseArray) {
        this.secondBeanSparseArray = secondBeanSparseArray;
    }

    public Context getmContext() {
        return mContext;
    }

    public void setmContext(Context mContext) {
        this.mContext = mContext;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new SecondViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_consume_second_layout, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
        SecondViewHolder secondViewHolder = (SecondViewHolder) viewHolder;
        secondViewHolder.tv.setText(secondBeanSparseArray.get(i).getChapterName());
        if (i == this.secondBeanSparseArray.size() - 1) {
            secondViewHolder.mView.setVisibility(View.GONE);
        } else {
            secondViewHolder.mView.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public int getItemCount() {
        return secondBeanSparseArray == null ? 0 : secondBeanSparseArray.size();
    }

    class SecondViewHolder extends RecyclerView.ViewHolder {
        TextView tv;
        View mView;

        public SecondViewHolder(@NonNull View itemView) {
            super(itemView);
            tv = itemView.findViewById(R.id.chapter_name_text);
            mView = itemView.findViewById(R.id.mView);
        }
    }

    /**
     * 更新数据
     *
     * @param secondBeanSparseArray
     */
    public void updata(List<ConsumptionDetailBean.ConsumptionItemsBean> secondBeanSparseArray) {
        this.secondBeanSparseArray = secondBeanSparseArray;
        notifyDataSetChanged();
    }

    /**
     * 清除数据
     */
    public void clear() {
        this.secondBeanSparseArray.clear();
        notifyDataSetChanged();
    }
}
